package com.security.config.security.authentication.common;

import com.security.domain.bo.R;
import com.security.utils.ResponseUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 会话过期策略
 *
 * @author DblSun
 */
@Component
public class MySessionExpiredHandler implements SessionInformationExpiredStrategy {

    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException {
        ResponseUtil.sendResponse(event.getResponse(),
                R.error(HttpServletResponse.SC_UNAUTHORIZED,
                        "您的账号已在另一台设备登录，本处下线，如非本人操作，请立即修改密码或冻结账号！"));
    }
}
